AWS S3 : Prevent Hotlinking policy
Problem :
Hosting a lot of photos or video files on AWS S3? Don't want other websites to link to your content or use your S3 as a free loader?
Solution :
Add new bucket policy to prevent hot linking. Go to the properties of the S3 bucket you want to prevent hot linking policy and click on the Add Bucket Policy button.
A modal box will appear and enter this policy :
{
"Version": "2008-10-17",
"Id": "preventHotLinking",
"Statement": [
{
"Sid": "1",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::your-s3-bucket/*",
"Condition": {
"StringLike": {
"aws:Referer": [
"http://yourwebsitename.com/*",
"http://www.yourwebsitename.com/*"
]
}
}
}
]
}
NOTE : Change your-s3-bucket and yourwebsitename.com to yours.
Reference :
https://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html
See also : WARNING: UNPROTECTED PRIVATE KEY FILE! error message
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+17.8k Golang : Check if a directory exist or not
+6.1k Unix/Linux : Use netstat to find out IP addresses served by your website server
+10.6k Golang : Get UDP client IP address and differentiate clients by port number
+6.8k Restart Apache or Nginx web server without password prompt
+6.3k Golang : Convert an executable file into []byte example
+16.4k Golang : Gzip file example
+24.2k Golang : Time slice or date sort and reverse sort example
+33.7k Golang : Call a function after some delay(time.Sleep and Tick)
+40.7k Golang : How to count duplicate items in slice/array?
+51k Golang : Check if item is in slice/array
+17.1k Golang : Get future or past hours, minutes or seconds
+17.2k Golang : Clone with pointer and modify value